package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC557 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String reverseWords(String s) {
            StringBuilder res = new StringBuilder();
            StringBuilder curStr = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                char curChar = s.charAt(i);
                if (curChar == ' ') {
                    res.append(curStr.toString() + " ");
                    curStr.delete(0, curStr.length());
                } else {
                    curStr.insert(0, curChar);
                }
            }
            if (curStr.length() > 0) {
                res.append(curStr.toString());
            }

            return res.toString();
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.reverseWords("Let's take LeetCode contest"));
    }

    public static void main(String[] args) throws Exception {
        LC557 an = new LC557();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
